#include "linked_common.h"
#include "sys_common.h"
struct Admin
{
    //唯一标识符
    int id;
    //char类型数组，字符串，存储姓名
    char *name;
    //char类型数组，字符串，存储密码
    char *password;
};
LinkedList adminlist;
//创建结构体实例
struct Admin a1={1,"admin1","123"};
struct Admin a2={2,"admin2","123"};
struct Admin a3={3,"admin3","123"};
struct Admin a4={4,"admin4","123"};
struct Admin a5={5,"admin5","123"};
//定义初始化函数
void init_admin_array(){
    init_linkedlist(&adminlist);
    //把实例一一保存到管理员数组admin_array[]中
    append(&adminlist,&a1);
    append(&adminlist,&a2);
    append(&adminlist,&a3);
    append(&adminlist,&a4);
    append(&adminlist,&a5);
}

//定义打印管理员函数
void print_admin_array(){
    printf("ID\t姓名\t密码\n");
    Node *node=adminlist.head;
    while (node)
    {
        struct Admin *a=node->data;
        printf("%d\t%s\t%s\n",a->id,a->name,a->password);
        node=node->next;
    }
}

//定义管理员登录，登录用户名和密码与管理员信息作对比，遍历比较管理员数组每条数据
bool login_admin(){
    printf("欢迎使用蓉华学员管理系统！\n");
    printf("请输入用户名和密码，用空格隔开\n");
    char name[50];
    char password[20];
    scanf("%s %s",name,password);
    Node *node=adminlist.head;
    while (node)
    {
        struct Admin *a=node->data;
        if (!strcmp(a->name,name)&&!strcmp(a->password,password))
        {
            return true;//匹配成功，返回true
        }
        node=node->next;
    }
    return false;//匹配失败，返回false
    
}